package com.ljx.offer;

import org.springframework.data.relational.core.sql.Conditions;

import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.locks.Condition;

/**
 * @author 李捷禧
 * Date: 2023/3/13
 * ClassName: C_25
 */

public class C_25 {

    public ListNode mergeTwoLists(ListNode l1, ListNode l2) {
        ListNode  list = new ListNode(0) , listNode = list;
        //两个链表都不为空再进入
        while(l1 != null && l2 != null){
            if(l1.val> l2.val){
                listNode.next = l2;
                l2 = l2.next;
            }else {
                listNode.next =l1;
                l1 = l1.next;
            }
            listNode = listNode.next;
        }
        //其中一个链不为空就接到listNode上
        listNode.next = l1 != null ? l1:l2;
        return list.next;
    }


    class ListNode {
        int val;
        ListNode next;
        ListNode(int x) {
            val = x;
        }
    }
}